
import os

from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from config.config import HOST, IMAGES_PATH, DATAS_PATH



#页面中的操作结果提示语元素定位
class BasePage:

    def __init__(self, driver):
        self.driver = driver
        self.url = "http://{}{}".format(HOST, self.url)

#打开指定页面
    def open(self):
        self.driver.get(self.url)

#解构locator
    def find_element(self, locator):
        return self.driver.find_element(*locator)

#find_elements方法
    def find_elements(self, locator):
        return self.driver.find_elements(*locator)

#组装图片的绝对路径
    def _get_abs_img(self, img):
        return os.path.join(IMAGES_PATH, img)

#组装数据文件的绝对路径
    def get_abs_file(self, filename):
        return os.path.join(DATAS_PATH, filename)

#实例化Alert对象
    def _alert(self):
        return Alert(self.driver)

#确认警告框
    def alert_accept(self):
        self._alert().accept()

#取消弹框
    def alert_dismiss(self):
        self._alert().dismiss()

#返回弹窗文本信息
    def get_alert_text(self):
        return self.driver.switch_to.alert.text




